package com.deparse.dpframe.ui.activity;

import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;

import com.deparse.dpframe.R;

/**
 * Created by MartinDKent on 2016/1/16.
 */
public class DPBaseActivityWithToolbar extends DPBaseActivity {
    private View contentView;
    private Toolbar toolbar;
    private ViewGroup bodyContainer;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        contentView = inflate(R.layout.dp_base_activity_with_toolbar);
        super.setContentView(contentView);
        toolbar = F(R.id.toolbar);
        setSupportActionBar(toolbar);

        bodyContainer = (RelativeLayout) contentView.findViewById(R.id.page_body);
    }

    public Toolbar getToolbar() {
        return toolbar;
    }

    @Override
    public void setContentView(int layoutResID) {
        this.setContentView(inflate(layoutResID));
    }

    @Override
    public void setContentView(View view) {
        this.setContentView(view, null);
    }

    @Override
    public void setContentView(View view, ViewGroup.LayoutParams params) {
        if (null == params) {
            params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        }
        bodyContainer.addView(view, params);
    }
}
